package com.geping.etl.common.security.pwd;

import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/***
 *  密码策略实现分发器
 * @author liang.xu
 * @date 2021.10.26
 */
@Slf4j
public abstract  class PwdPolicyServiceDispatcher {

     private static Map<String, PwdPolicyService> validators=new HashMap<>();


     public PwdPolicyServiceDispatcher(){
         PwdPolicyService pwdPolicyService= (PwdPolicyService) this;
         validators.put(pwdPolicyService.getType(),pwdPolicyService);
     }

    public static  PwdPolicyService  getPwdPolicyService(String type){
        log.info("pwd validator type : {} ",type);
        PwdPolicyService  pwdPolicyService= validators.get(type);
        if(Objects.isNull(pwdPolicyService)){
            pwdPolicyService=validators.get(PwdPolicyConstant.DEFAULT_POLICY);
            return pwdPolicyService;
        }
        return pwdPolicyService;
    }

}